//
//  CQueue.hpp
//  CppDemo
//
//  Created by 蒋益杰 on 2017/3/4.
//  Copyright © 2017年 com.ed. All rights reserved.
//

#ifndef CQueue_hpp
#define CQueue_hpp

#include <stdio.h>
#include <iostream>
#include <stack>

using namespace std;

template <typename T>
class CQueue {
    
public:
//    CQueue(void);
//    ~CQueue(void);
    
    void appendTail(const T& node);
    T deleteHead();
    void print();
    
private:
    stack<T> stk1;
    stack<T> stk2;
};

template <typename T>
void CQueue<T>::print() {
    cout << "stk1 size = " << stk1.size() << endl;
    cout << "stk2 size = " << stk2.size() << endl;
}

template <typename T>
void CQueue<T>::appendTail(const T& node) {
    stk1.push(node);
}

template <typename T>
T CQueue<T>::deleteHead() {
    if (stk2.empty()) {
        while (stk1.size() > 0) {
            T &data = stk1.top();
            stk1.pop();
            stk2.push(data);
        }
    }
    
    if (stk2.size() > 0) {
        T head = stk2.top();
        stk2.pop();
        return head;
    }
    
    return NULL;
}



#endif /* CQueue_hpp */
